#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (auto &x : a) cin >> x;
    ll posi = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] > 0)
        posi += a[i];
      else if (a[i] < 0 && posi > 0) {
        ll minu = min(-a[i], posi);
        a[i] += minu;
        posi -= minu;
      }
    }
    ll coin = 0;
    for (auto x : a) {
      if (x < 0) coin += (-x);
    }
    cout << coin << endl;
  }
}
